package com.keller.guli.service.edu.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keller.guli.service.base.dto.CourseDto;
import com.keller.guli.service.edu.entity.Course;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.keller.guli.service.edu.entity.vo.CoursePublishVo;
import com.keller.guli.service.edu.entity.vo.CourseVo;
import com.keller.guli.service.edu.entity.vo.WebCourseVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 课程 Mapper 接口
 * </p>
 *
 * @author keller
 * @since 2020-07-21
 */
@Repository
public interface CourseMapper extends BaseMapper<Course> {

    //mp会自动组装queryWrapper：
    //@Param(Constants.WRAPPER) 和 xml文件中的 ${ew.customSqlSegment} 对应
    //SELECT c.id,c.title,c.lesson_num,c.price,c.cover,c.buy_count,c.view_count,c.status,c.gmt_create,et.
    //NAME AS teacherName,es.title AS subjectParentTitle, es1.title AS subjectTitle
    //FROM edu_course c
    //LEFT JOIN edu_teacher et ON c.`teacher_id`=et.`id`
    //LEFT JOIN edu_subject es ON c.`subject_parent_id`=es.`id`
    //LEFT JOIN edu_subject es1 ON c.`subject_id`=es1.`id`
    List<CourseVo> selectPageByCourseQueryVo(Page<CourseVo> pageParam,  @Param(Constants.WRAPPER)QueryWrapper<CourseVo> queryWrapper);

    //SELECT c.`id`,c.`title`,c.`lesson_num`,es.`title`,es1.`title`,et.`name`,c.`price`
    //FROM edu_course c
    //LEFT JOIN edu_subject es ON c.`subject_parent_id`=es.`id`
    //LEFT JOIN edu_subject es1 ON c.`subject_id`=es1.`id`
    //LEFT JOIN edu_teacher et ON c.`teacher_id`=et.`id`
    CoursePublishVo selectCoursePublishVoById(String id);

    // 根据课程id查询webCourseVo
    //SELECT c.`id`,c.`title`,c.`price`,c.`cover`,c.`buy_count`,c.`view_count`,edc.`description`,c.`teacher_id`,
    //et.`name`,et.`intro`,et.`avatar`,
    //c.`subject_parent_id` AS subjectOneId,c.`subject_id` AS subjectTwoId,
    //es1.`title` AS subjectOneTiele,es2.`title` AS subjectTwoTitle
    //FROM
    //edu_course c
    //LEFT JOIN edu_course_description edc ON c.`id`=edc.`id`
    //LEFT JOIN edu_teacher et ON c.`teacher_id`=et.`id`
    //LEFT JOIN edu_subject es1 ON c.`subject_parent_id`=es1.`id`
    //LEFT JOIN edu_subject es2 ON c.`subject_id`=es2.`id`
    WebCourseVo selectWebCourseVoById(String courseId);

    CourseDto selectCourseDtoById(String courseId);
}
